#include "videoview.h"
#include <QFileDialog>

VideoView::VideoView()
{

}

void VideoView::init(QWidget *qWidge,Ui::MainWindow *ui)
{
    this->ui = ui;
    this->qWidge = qWidge;

    connect(ui->pushButtonOpenVideoFile,SIGNAL(clicked()),this,SLOT(on_pushButtonOpenVideoFile_clicked()));
    connect(ui->pushButtonVideoStart,SIGNAL(clicked()),this,SLOT(on_pushButtonVideoStart_clicked()));
    connect(&videoThread,SIGNAL(videoStatusSignals(int,QString)),this,SLOT(videoStatusSlots(int,QString)));

    QString binFilePath = settings->value("video_file_path").toString();
    if(!binFilePath.isEmpty())
    {
        ui->lineEditVideoFilePath->setText(binFilePath);
    }
}

void VideoView::on_pushButtonOpenVideoFile_clicked()
{
    QString path = settings->value("video_file_path").toString();
    QString strFile = QFileDialog::getOpenFileName(
                qWidge,
                tr("打开文件"),
                path);

    if(!strFile.isEmpty())
    {
        settings->setValue("video_file_path",strFile);
        ui->lineEditVideoFilePath->setText(strFile);
    }
}

void VideoView::on_pushButtonVideoStart_clicked()
{
    QString binFilaPath = ui->lineEditVideoFilePath->text();
    if(!binFilaPath.isEmpty())
    {
        ui->pushButtonVideoStart->setEnabled(false);

        videoThread.setPath(binFilaPath);
        videoThread.start();
    }else{
        mlog.show("请加载固件地址");
    }

}

void VideoView::videoStatusSlots(int staus,QString str)
{
    if(staus >= 0)
    {
        //flashProgressBar->setValue(staus);
    }else if(staus == -2)
    {
        ui->pushButtonFlashStart->setEnabled(true);
    }else if(staus == -3)
    {
        if(str != NULL)
        {
            ui->lineEditFlashFilePath->setText(str+"/video.gl");
            settings->setValue("bin_file_path",str+"/video.gl");
            return;
        }
    }

    mlog.show(str);
}
